package com.wannengbang.cloudleader.homepage;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.gyf.immersionbar.ImmersionBar;
import com.wannengbang.cloudleader.R;
import com.wannengbang.cloudleader.base.BaseActivity;
import com.wannengbang.cloudleader.base.DataCallBack;
import com.wannengbang.cloudleader.bean.DeviceNumberBean;
import com.wannengbang.cloudleader.bean.UserInfoBean;
import com.wannengbang.cloudleader.homepage.model.HomePageModelImpl;
import com.wannengbang.cloudleader.utils.SPManager;
import com.wannengbang.cloudleader.widget.AppTitleBar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MachinesClassifyActivity extends BaseActivity {

    @BindView(R.id.title_bar)
    AppTitleBar titleBar;
    @BindView(R.id.tv_total_num)
    TextView tvTotalNum;
    @BindView(R.id.tv_normal_number)
    TextView tvNormalNumber;
    @BindView(R.id.tv_send_number)
    TextView tvSendNumber;
    @BindView(R.id.ll_jiju_bg)
    LinearLayout llJijuBg;
    @BindView(R.id.ll_look1)
    LinearLayout llLook1;
    @BindView(R.id.ll_look2)
    LinearLayout llLook2;
    @BindView(R.id.tv_big_normal_number)
    TextView tvBigNormalNumber;
    @BindView(R.id.ll_look3)
    LinearLayout llLook3;
    @BindView(R.id.tv_vipNumber)
    TextView tvVipNumber;
    @BindView(R.id.ll_look4)
    LinearLayout llLook4;
    @BindView(R.id.tv_plusNumber)
    TextView tvPlusNumber;
    @BindView(R.id.ll_look5)
    LinearLayout llLook5;
    @BindView(R.id.ll_look13)
    LinearLayout llLook13;
    @BindView(R.id.ll_look14)
    LinearLayout llLook14;
    @BindView(R.id.tv_vipNumber2)
    TextView tvVipNumber2;
    @BindView(R.id.ll_look41)
    LinearLayout llLook41;
    @BindView(R.id.tv_plusNumber2)
    TextView tvPlusNumber2;
    @BindView(R.id.ll_look51)
    LinearLayout llLook51;
    @BindView(R.id.ll_look15)
    LinearLayout llLook15;

    @BindView(R.id.tv_yunxiaobao_envelope_version)
    TextView tv_yunxiaobao_envelope_version;
    @BindView(R.id.tv_zs_yunxiaobao_envelope_version)
    TextView tv_zs_yunxiaobao_envelope_version;


    private int child_agent_id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_machines_classify);
        ButterKnife.bind(this);
        ImmersionBar.with(this)
                .statusBarDarkFont(false)
                .navigationBarDarkIcon(true)
                .navigationBarColor(R.color.white)
                .statusBarDarkFont(false, 0.2f)
                .init();
        initView();
    }

    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }

    private void initView() {
        UserInfoBean userInfoBean = new Gson().fromJson(SPManager.getInstance().getUserInfoJson(), UserInfoBean.class);
        if (userInfoBean != null) {
            child_agent_id = userInfoBean.getData().getId();
            //2标记隐藏
            if ("17329409714".equals(userInfoBean.getData().getMobile()) || "13403854628".equals(userInfoBean.getData().getMobile())) {
                llJijuBg.setBackgroundResource(R.mipmap.ic_jiju_bg2);
            } else {
                llJijuBg.setBackgroundResource(R.mipmap.ic_jiju_bg);
            }
        }
    }

    private void initData() {
        new HomePageModelImpl().requestChildDeviceDeviceNumber(new DataCallBack<DeviceNumberBean>() {
            @Override
            public void onSuccessful(DeviceNumberBean bean) {
                tvNormalNumber.setText(bean.getData().getNormal_number() + "");
                tvSendNumber.setText(bean.getData().getSend_number() + "");
                tvBigNormalNumber.setText(bean.getData().getBigNormalNumber() + "");
                tvVipNumber.setText(bean.getData().getVipNumber() + "");
                tvPlusNumber.setText(bean.getData().getPlusNumber() + "");
                tvVipNumber2.setText(bean.getData().getSendVipNumber() + "");
                tvPlusNumber2.setText(bean.getData().getSendPlusNumber() + "");


                tv_yunxiaobao_envelope_version.setText(bean.getData().getHbNumber() + "");
                tv_zs_yunxiaobao_envelope_version.setText(bean.getData().getSendHbNumber() + "");


                int totalNum = bean.getData().getNormal_number() + bean.getData().getSend_number()
                        + bean.getData().getBigNormalNumber() + bean.getData().getVipNumber()
                        + bean.getData().getPlusNumber() + bean.getData().getSendVipNumber()
                        + bean.getData().getSendPlusNumber();
                tvTotalNum.setText(totalNum + "");
            }

            @Override
            public void onFailed(String msg, String code) {

            }
        });
    }

    //type=1 云小宝 普通版
    //type=2 云商宝
    //type=3 云小宝 vip版
    //type=4 云小宝 plus版
    @OnClick({R.id.ll_look15, R.id.ll_look1, R.id.ll_look2, R.id.ll_look3, R.id.ll_look4, R.id.ll_look5, R.id.ll_look41, R.id.ll_look51, R.id.ll_look13, R.id.ll_look14, R.id.ll_look7, R.id.ll_look8})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_look1:
                //采购的机具 云小宝
                Intent intent = new Intent(mActivity, MachinesDetailsActivity.class);
                intent.putExtra("type", "1");
                intent.putExtra("child_agent_id", child_agent_id + "");
                intent.putExtra("agent_name", "");
                intent.putExtra("is_send", "0");
                startActivity(intent);
                break;
            case R.id.ll_look2:
                //兑换的机具  云小宝
                intent = new Intent(mActivity, MachinesDetailsActivity.class);
                intent.putExtra("type", "1");
                intent.putExtra("child_agent_id", child_agent_id + "");
                intent.putExtra("agent_name", "");
                intent.putExtra("is_send", "1");
                startActivity(intent);
                break;
            case R.id.ll_look3:
                //采购的机具  云商宝
                intent = new Intent(mActivity, MachinesDetailsActivity.class);
                intent.putExtra("type", "2");
                intent.putExtra("child_agent_id", child_agent_id + "");
                intent.putExtra("agent_name", "");
                intent.putExtra("is_send", "0");
                startActivity(intent);
                break;
            case R.id.ll_look4:
                // 云小宝 vip
                intent = new Intent(mActivity, MachinesDetailsActivity.class);
                intent.putExtra("type", "3");
                intent.putExtra("child_agent_id", child_agent_id + "");
                intent.putExtra("agent_name", "");
                intent.putExtra("is_send", "0");
                startActivity(intent);
                break;
            case R.id.ll_look7:
                // 云小宝红包
                intent = new Intent(mActivity, MachinesDetailsActivity.class);
                intent.putExtra("type", "5");
                intent.putExtra("child_agent_id", child_agent_id + "");
                intent.putExtra("agent_name", "");
                intent.putExtra("is_send", "0");
                startActivity(intent);
                break;
            case R.id.ll_look8:
                // 赠送的云小宝红包版
                intent = new Intent(mActivity, MachinesDetailsActivity.class);
                intent.putExtra("type", "5");
                intent.putExtra("child_agent_id", child_agent_id + "");
                intent.putExtra("agent_name", "");
                intent.putExtra("is_send", "1");
                startActivity(intent);
                break;
            case R.id.ll_look41:
                // 云小宝 vip 兑换的
                intent = new Intent(mActivity, MachinesDetailsActivity.class);
                intent.putExtra("type", "3");
                intent.putExtra("child_agent_id", child_agent_id + "");
                intent.putExtra("agent_name", "");
                intent.putExtra("is_send", "1");
                startActivity(intent);
                break;
            case R.id.ll_look5:
                //云小宝 plus
                intent = new Intent(mActivity, MachinesDetailsActivity.class);
                intent.putExtra("type", "4");
                intent.putExtra("child_agent_id", child_agent_id + "");
                intent.putExtra("agent_name", "");
                intent.putExtra("is_send", "0");
                startActivity(intent);
                break;
            case R.id.ll_look51:
                //云小宝 plus
                intent = new Intent(mActivity, MachinesDetailsActivity.class);
                intent.putExtra("type", "4");
                intent.putExtra("child_agent_id", child_agent_id + "");
                intent.putExtra("agent_name", "");
                intent.putExtra("is_send", "1");
                startActivity(intent);
                break;
            case R.id.ll_look13:
                showActivity(ExchangeTransformActivity.class);
                break;
            case R.id.ll_look14:
                showActivity(ExchangeTransformListActivity.class);
                break;
            case R.id.ll_look15:
                intent = new Intent(mActivity, ApplyVipListActivity.class);
                startActivity(intent);
                break;
        }
    }
}
